package com.wzh.core.config;

import com.wzh.core.api.LoadBalance;
import com.wzh.core.api.Router;
import com.wzh.core.api.balance.RandomLoadBalance;
import com.wzh.core.api.balance.RoundLoadBalance;
import com.wzh.core.consumer.ConsumerBootstrap;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * @description: 消费者配置
 * @author: wangzouhuax
 */
@Configuration
public class ConsumerConfig {

    @Bean
    public ConsumerBootstrap buildConsumerBootstrap() {
        return new ConsumerBootstrap();
    }


    /**
     * 启动消费者服务后扫描所有标记了@RpcConsumer 注解的属性，进行代理
     */
    @Bean
    @Order(Integer.MIN_VALUE)
    public ApplicationRunner runScannerConsumerServiceField(ConsumerBootstrap consumerBootstrap) {
        return args -> {
            consumerBootstrap.screenConsumerServiceFields();
        };
    }

    @Bean
    public Router router() {
        return Router.ROUTER_DEFAULT;
    }

    @Bean
    public LoadBalance loadBalance() {
        return new RoundLoadBalance();
    }
}
